﻿using Framework.EditorDependency;
using UnityEditor;
using UnityEngine;

namespace Framework.Editor
{
    public class DoDoveEditorSceneUI {
        public static void Initial()
        {
            SceneView.duringSceneGui += OnSceneGUI;
        }


        static void OnSceneGUI(SceneView sceneView)
        {
            OnDrawUIEditorGUI();
        }

        static void OnDrawUIEditorGUI()
        {
            Handles.BeginGUI();
            GUILayout.BeginArea(new Rect(100, 30, 100, 300));
            GUILayout.BeginVertical(GUILayout.Width(80));

            GUI.skin.button.fontSize = 10;
            GUI.color = Color.green;
            if (GUILayout.Button("添加引用"))
            {
                if (Selection.activeGameObject != null)
                {
                    Selection.activeGameObject.AddComponent<DodoveDeclearUIType>();
                }
                else
                {
                    Debug.Log("没有选定 添加引用脚本");
                }
     
            }

            GUILayout.Space(20);
   
            if (GUILayout.Button("创建UI"))
            {
                DoDoveCreatePrefab.AutoCreatePrefab();
            }
            GUILayout.EndVertical();
            GUILayout.EndArea();
            Handles.EndGUI();
        }
    }
    
    [InitializeOnLoad]
    public class HierarchyComponentMarker
    {
        static HierarchyComponentMarker()
        {
            // 注册 Hierarchy 窗口的绘制回调
            EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyWindowItemOnGUI;
        }
 
        private static void OnHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
        {
            // 获取 GameObject
            GameObject gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
            if (gameObject != null)
            {
         
                if (gameObject.GetComponent<DodoveDeclearUIType>() != null)
                {
                    Rect labelRect = new Rect(selectionRect);
                    labelRect.x += labelRect.width - 20;
                    labelRect.width = 20;
                    GUI.Label(labelRect, "★"); 
                }
            }
        }
    }
    
}